home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_10_08
/
qcdemow.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1992-07-20
|
22KB
|
631 lines
///////////////////////////////////////////////////////
// QCDEMOW.CPP: Quadcode demo program for Windows
// Written by:
// Kenneth Van Camp
// RR #1 Box 1255
// East Stroudsburg, PA 18301
// (717)223-8620
//
// Functions -
// main main pgm entry point
// init_graphics initialize graphics
// Cursor::Cursor default constructor
// Cursor::Move move cursor
// RegionDisplay::Display display region
// RegionDisplay::Interact user interaction
// win_yieldfunc yield function for build
//
///////////////////////////////////////////////////////
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include <iostream.h>
#include "qc.h"
#include "qcdemow.h"
// Global variables:
HCURSOR ArrowCursor, // standard arrow cursor
WaitCursor; // hourglass cursor
HDC Hdc; // device context for the window
HWND BuildHdlg, // handle for the Building dialog box
MainHwnd; // handle for application's main window
HANDLE Haccel; // handle for application acclerators
int Shrink = TRUE, // shrink all qc's for plotting?
XShrinkage = 0, // amount to shrink in X direction
YShrinkage = 0, // amount to shrink in Y direction
Xmax = 0, // # pixels in viewport in X direction
Ymax = 0, // # pixels in viewport in Y direction
QCsize, // size of a single-division quadcode
Nquits, // number of quits used to represent region
RegionNumQC = 0, // number of qc's in region
BuildCancelled = FALSE; // was the region building cancelled?
time_t RegionBuildTime = 0;// time to build region
const int SCRRES = 1024; // screen resolution used (logical coords)
// class RegionDisplay: A Region class with graphical
// display and interaction capabilities.
class RegionDisplay: public Region
{
public:
RegionDisplay // constructor from outline
(PointListHeader &vertex_list):
Region (vertex_list) { } // calls base constr.
void Display (void); // display on graphics screen
void Interact (void); // graphic interact function
}; // class RegionDisplay
RegionDisplay *TheRegion = NULL;
// The following is the perimeter list for the demo region:
const int Npts = 37;
const int Ndiv = 128;
const int Reduce = 1;
Point Plist[Npts] =
{
{ 5, 68}, { 28, 68}, { 32, 88}, { 33, 94},
{ 31,110}, { 30,113}, { 35,124}, { 51,125},
{ 63,127}, { 63,119}, { 67,116}, { 59,109},
{ 63,119}, { 63,127}, { 74,126}, { 80,125},
{ 88,112}, { 99,101}, {107, 98}, {113, 96},
{124, 98}, {122, 94}, {123, 91}, {121, 85},
{118, 78}, {108, 73}, { 96, 64}, { 85, 58},
{ 81, 50}, { 82, 46}, { 90, 38}, { 83, 25},
{ 72, 21}, { 58, 8}, { 55, 8}, { 54, 40},
{ 5, 40},
};
PointListHeader Phdr =
{
Npts, Ndiv, Plist
};
// Prototypes for exported functions:
#if defined( __cplusplus )
extern "C" {
#endif // __cplusplus
long FAR PASCAL WndProc (HWND, UINT, WPARAM, LPARAM);
BOOL FAR PASCAL AboutDlgProc (HWND, UINT, WPARAM, LPARAM);
BOOL FAR PASCAL BuildDlgProc (HWND, UINT, WPARAM, LPARAM);
#if defined( __cplusplus )
}
#endif // __cplusplus
// Prototypes for other local functions:
void redraw_win (int first_time);
void update_status (int xcursor, int ycursor);
void set_draw_area (void);
int win_yieldfunc (int pct_complete);
int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpszCmdParam, int nCmdShow)
{
static char szAppName[] = "QCDemoW";
MSG msg;
WNDCLASS wndclass;
// Initialize the cursor we will use.
ArrowCursor = LoadCursor (NULL, IDC_ARROW);
WaitCursor = LoadCursor (NULL, IDC_WAIT);
if (!hPrevInstance)
{
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hCursor = ArrowCursor;
wndclass.hbrBackground = GetStockObject (WHITE_BRUSH);
wndclass.lpszMenuName = "QCDEMOW";
wndclass.lpszClassName = szAppName;
RegisterClass (&wndclass);
}
MainHwnd = CreateWindow (szAppName, // window class name
"Quadcode Demo (Windows Version)", // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL); // creation parameters
ShowWindow (MainHwnd, nCmdShow);
UpdateWindow (MainHwnd);
Haccel = LoadAccelerators (hInstance, "ACCELERATORS_1");
if (Haccel == NULL)
MessageBox (MainHwnd, "Can't Load Acelerators", "NOTICE",
MB_ICONEXCLAMATION | MB_OK);
while (GetMessage (&msg, NULL, 0, 0))
{
// Translate accelerator keystrokes, too.
if (! TranslateAccelerator (MainHwnd, Haccel, &msg))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
return msg.wParam;
} // WinMain
long FAR PASCAL WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
int ret;
WORD menu_state; // Current menu state (checked or not)
char tmpstr[80];
static int first_paint = TRUE, // Is this the first screen paint?
resized = FALSE; // Was the window just resized?
static HMENU menu; // Popup menu
static HANDLE hinstance; // Instance of this program
static FARPROC about_dlg_proc, // Point to About dialog box procedure
build_dlg_proc; // Point to Build dialog box procedure
switch (message)
{
case WM_CREATE:
// This occurs when the window is first created.
// First get the instance of the main program.
hinstance = ((LPCREATESTRUCT)lParam)->hInstance;
// Register the dialog procedures:
about_dlg_proc = MakeProcInstance ((FARPROC)AboutDlgProc,
hinstance);
build_dlg_proc = MakeProcInstance ((FARPROC)BuildDlgProc,
hinstance);
// Then get the handle for the menu
menu = GetMenu (hwnd);
return 0;
case WM_COMMAND:
// This is a menu selection or accelerator.
// Ignore any menu commands if the region is not built yet.
if (RegionNumQC == 0)
return 0;
switch ( wParam )
{
case QCMNU_EXIT: // File Menu, Exit QCDemoW selection
case QCACC_EXIT: // Alt-X accelerator
ret = MessageBox (hwnd, "Are You Sure You Want To Exit?",
"QCDemoW", MB_OKCANCEL);
if ( ret == IDOK )
PostQuitMessage (0);
return 0;
case QCMNU_ABOUT: // File Menu, About selection
DialogBox (hinstance, "ABOUT_BOX", hwnd, about_dlg_proc);
return 0;
case QCMNU_SHRINKAGE: // Options Menu, Shrinkage selection
case QCACC_SHRINKAGE: // Alt-S accelerator
// This is a boolean checked item: Reverse previous state.
if (Shrink)